'use client'

import { useState } from 'react'
import { Box } from '@chakra-ui/react'
import { MainLayout } from '@/components/layout/MainLayout'
import { Header } from '@/components/layout/Header'
import { EditorLayout } from '@/components/layout/EditorLayout'
import { ProjectSidebar } from '@/components/layout/ProjectSidebar'
import { AISidebar } from '@/components/layout/AISidebar'

export default function AppPage() {
  const [showAI, setShowAI] = useState(true)

  // AI侧边栏切换处理函数
  const handleToggleAI = () => {
    setShowAI(!showAI);
  };

  // AI侧边栏关闭处理函数
  const handleCloseAI = () => {
    setShowAI(false);
  };

  // 示例项目和章节数据
  const sampleProjects = [
    { id: '1', title: 'The Last Kingdom', chapters: [
      { id: '1', title: 'Chapter 1: The Beginning' },
      { id: '2', title: 'Chapter 2: The Journey' },
    ]},
    { id: '2', title: 'Starlight Dreams', chapters: [
      { id: '3', title: 'Chapter 1: First Contact' },
    ]},
  ]

  const sampleStory = `Kael ducked beneath a low-hanging branch, his breath forming clouds in the cold morning air. The forest was silent save for the occasional rustle of leaves. He knew Lira would be waiting at the edge of the clearing, as she always did at dawn.

The mist was thick between the trees, lending an otherworldly quality to the forest. It was in these moments—alone with his thoughts—that Kael felt most at peace. The kingdom and its politics seemed far away here.

When he reached the clearing, Lira was indeed waiting, her silver hair catching what little sunlight filtered through the canopy. She turned at the sound of his approach, a rare smile lighting her normally serious face.

"You're late," she said, though there was no admonishment in her voice.

"The guard rotation changed," Kael replied. "I had to take a different path."

Lira nodded, understanding the risks he took in meeting her. As the daughter of the neighboring kingdom's ruler, these clandestine meetings could be seen as treason. But they had grown up together, before borders and politics had forced them apart.

"I've discovered something," Lira said, her voice dropping to a whisper. "Something about the ancient ruins. I think the legends might be true after all."`;

  return (
    <Box h="100vh" display="flex" flexDirection="column">
      <Header onToggleAI={handleToggleAI} />
      <Box flex="1" overflow="hidden">
        <MainLayout 
          leftSidebar={<ProjectSidebar projects={sampleProjects} />}
          mainContent={
            <EditorLayout 
              title="The Last Kingdom" 
              subtitle="Chapter 1: The Beginning" 
              wordCount={1245}
            >
              {sampleStory}
            </EditorLayout>
          }
          rightSidebar={<AISidebar onClose={handleCloseAI} />}
          showRightSidebar={showAI}
        />
      </Box>
    </Box>
  )
} 